<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>API测试页面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 50px auto;
            padding: 20px;
        }
        .test-section {
            margin: 20px 0;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
        .result {
            background: #f5f5f5;
            padding: 10px;
            margin: 10px 0;
            border-radius: 3px;
            white-space: pre-wrap;
        }
        button {
            padding: 10px 20px;
            margin: 5px;
            background: #007bff;
            color: white;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }
        button:hover {
            background: #0056b3;
        }
    </style>
</head>
<body>
    <h1>API测试页面</h1>
    
    <div class="test-section">
        <h3>测试朋友列表API</h3>
        <button onclick="testFriendList()">测试获取朋友列表</button>
        <div id="friendListResult" class="result"></div>
    </div>
    
    <div class="test-section">
        <h3>测试朋友详情API</h3>
        <input type="number" id="friendId" placeholder="输入朋友ID" value="1">
        <button onclick="testFriendDetail()">测试获取朋友详情</button>
        <div id="friendDetailResult" class="result"></div>
    </div>
    
    <div class="test-section">
        <h3>测试搜索API</h3>
        <input type="text" id="searchName" placeholder="输入搜索姓名" value="张三">
        <button onclick="testSearch()">测试搜索</button>
        <div id="searchResult" class="result"></div>
    </div>
    
    <div class="test-section">
        <h3>测试筛选API</h3>
        <input type="text" id="filterRelationship" placeholder="输入关系" value="同学">
        <button onclick="testFilter()">测试筛选</button>
        <div id="filterResult" class="result"></div>
    </div>
    
    <script>
        function testFriendList() {
            const resultDiv = document.getElementById('friendListResult');
            resultDiv.textContent = '测试中...';
            
            fetch('/friend/api/list')
                .then(response => response.json())
                .then(data => {
                    resultDiv.textContent = JSON.stringify(data, null, 2);
                })
                .catch(error => {
                    resultDiv.textContent = '错误: ' + error.message;
                });
        }
        
        function testFriendDetail() {
            const friendId = document.getElementById('friendId').value;
            const resultDiv = document.getElementById('friendDetailResult');
            resultDiv.textContent = '测试中...';
            
            fetch(`/friend/api/detail/${friendId}`)
                .then(response => response.json())
                .then(data => {
                    resultDiv.textContent = JSON.stringify(data, null, 2);
                })
                .catch(error => {
                    resultDiv.textContent = '错误: ' + error.message;
                });
        }
        
        function testSearch() {
            const searchName = document.getElementById('searchName').value;
            const resultDiv = document.getElementById('searchResult');
            resultDiv.textContent = '测试中...';
            
            fetch(`/friend/api/search?name=${encodeURIComponent(searchName)}`)
                .then(response => response.json())
                .then(data => {
                    resultDiv.textContent = JSON.stringify(data, null, 2);
                })
                .catch(error => {
                    resultDiv.textContent = '错误: ' + error.message;
                });
        }
        
        function testFilter() {
            const relationship = document.getElementById('filterRelationship').value;
            const resultDiv = document.getElementById('filterResult');
            resultDiv.textContent = '测试中...';
            
            fetch(`/friend/api/filter?relationship=${encodeURIComponent(relationship)}`)
                .then(response => response.json())
                .then(data => {
                    resultDiv.textContent = JSON.stringify(data, null, 2);
                })
                .catch(error => {
                    resultDiv.textContent = '错误: ' + error.message;
                });
        }
    </script>
</body>
</html>
